package com.flx.dis.mq.rocket.service.consumer;

import com.flx.common.utils.json.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * @Author: Fenglixiong
 * @Date: 2021/6/23 11:43
 * @Description:
 *
 * 每个消费者组维护一个线程池核心数量为20
 *
 * 每个主机同一个消费组实例只能创建一次，可以设置为集群模式，其他机器可以同样订阅，会负载均衡消费
 */
@Slf4j
@Component
public class RocketConsumer {

    /**
     * nameServer: MQ地址
     * consumerGroup: 消费组
     * selectorExpression: tag名字
     * consumeMode: 消费模式--concurrently异步多线程消费--orderly顺序消费
     * messageModel: 消息模式--cluster集群模式--broadcast广播模式
     */
    @Component
    @RocketMQMessageListener(topic = "flx-student",consumerGroup = "student-group-001",selectorExpression = "aaa")
    public class StudentConsumer01 implements RocketMQListener {

        @Override
        public void onMessage(Object o) {
            log.info(">>>>>A=>{} {} {}",Thread.currentThread().getId(),Thread.currentThread().getName(), JsonUtils.toJsonMsg(o));
        }
    }

    @Component
    @RocketMQMessageListener(topic = "flx-student",consumerGroup = "student-group-002",selectorExpression = "bbb")
    public class StudentConsumer02 implements RocketMQListener{

        @Override
        public void onMessage(Object o) {
            log.info(">>>>>B=>{} {} {}",Thread.currentThread().getId(),Thread.currentThread().getName(), JsonUtils.toJsonMsg(o));
        }
    }



}
